package com.fms.gui.templateCreator.components.date;

import java.awt.BorderLayout;
import java.awt.Font;
import java.util.Calendar;

import javax.swing.BorderFactory;
import javax.swing.JPanel;

import org.freixas.jcalendar.DateEvent;
import org.freixas.jcalendar.DateListener;
import org.freixas.jcalendar.JCalendar;

import com.fms.model.factory.parts.IDateSelector;

public class DateSelector extends JPanel implements IDateSelector, DateListener
{
	/**
	 * 
	 */
	private static final long	serialVersionUID	= 443028553503039970L;
	private Calendar calendar;
	
	public DateSelector(Calendar when)
	{
		this.setLayout(new BorderLayout());
		this.setBorder(BorderFactory.createEtchedBorder());
		JCalendar calendarComponent = new JCalendar( JCalendar.DISPLAY_DATE | JCalendar.DISPLAY_TIME, true);

		this.add(calendarComponent);
		
		// Set fonts rather than using defaults

		if(when == null)
		{
			when = Calendar.getInstance();
		}
		
		calendar = when;
		calendarComponent.setDate(when.getTime());
		calendarComponent.addDateListener(this);
		
		calendarComponent.setTitleFont(new Font("Serif", Font.BOLD|Font.ITALIC, 24));
		calendarComponent.setDayOfWeekFont(new Font("SansSerif", Font.ITALIC, 12));
		calendarComponent.setDayFont(new Font("SansSerif", Font.BOLD, 16));
		calendarComponent.setTimeFont(new Font("DialogInput", Font.PLAIN, 20));
		calendarComponent.setTodayFont(new Font("Dialog", Font.PLAIN, 14));
		
		
	}

	
	public Calendar getTime()
	{
		return calendar;
	}

	
	public void dateChanged(DateEvent arg)
	{
		calendar = arg.getSelectedDate();
		
	}
	
	
}
